﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace OISTools
{
    public partial class ConvertUTF : Form
    {
        public ConvertUTF()
        {
            InitializeComponent();
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            DirectoryInfo dinfo=new DirectoryInfo(textBox1.Text);

            foreach (FileInfo finfo in dinfo.GetFiles())
            {
                if (finfo.Extension.EndsWith("sql") || finfo.Extension.EndsWith("txt"))
                {
                    string filename = finfo.FullName;
                    StreamReader sr = new StreamReader(filename, Encoding.GetEncoding("gb2312"));
                    string text = sr.ReadToEnd();
                    sr.Close();
                    StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8);
                    sw.Write(text);
                    sw.Flush();
                    sw.Close();
                }
            }
        }

        private void btnGetFiles_Click(object sender, EventArgs e)
        {
            DirectoryInfo dinfo = new DirectoryInfo(textBox1.Text);

            foreach (FileInfo finfo in dinfo.GetFiles())
            {
                if (finfo.Extension.EndsWith("sql") || finfo.Extension.EndsWith("txt"))
                {
                    string filename = finfo.Name;
                    richTextBox1.Text += filename+"\n";
                }
            }
        }
    }
}
